package com.dtp.core;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.InitializingBean;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author evolution
 * @title: DtpMonitor
 * @projectName dtp-nacos
 * @description: TODO
 * @date 2022-10-21 11:37
 */
public class DtpMonitor implements InitializingBean {
    
    ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
    
    
    @Override
    public void afterPropertiesSet() throws Exception {
    executor.scheduleAtFixedRate(()->{
        for(ConcurrentHashMap.Entry<String,DtpExecutor> executorEntry :DtpUtil.map.entrySet()){
            String name =executorEntry.getKey();
            DtpExecutor executor = executorEntry.getValue();
            int activeCount = executor.getActiveCount();
            if(activeCount>3){
                System.out.printf("警告！%s线程池的活跃线程数是：%s",name,activeCount);
            }
        }
    },5,5, TimeUnit.SECONDS);
    }
}
